package com.qk2;

import java.lang.reflect.Field;

public class MyObjectFactory {
	public Object getObject(String className){
		try {
			
			Class c=Class.forName(className);
			Object o=c.newInstance();
			Field[] field=c.getDeclaredFields();
			
			for (Field field2 : field) {		
				
				if(field2.getGenericType().equals(String.class)){
					field2.setAccessible(true);
					field2.set(o, field2.getName()+" initial value");
				}
				
				if(field2.getGenericType().equals(double.class)){
					field2.setAccessible(true);
					field2.set(o, 1.0);
				}
				if(field2.getGenericType().equals(int.class)){
					field2.setAccessible(true);
					field2.set(o, 1);
				}
			}
			
			
			return o;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
